// 角色管理模块的接口
import request from '@/utils/request'
// 引入类型
import type {
  Role,
  RoleResponseData,
  MenuResponseData,
} from '@/api/acl/role/type'

// 枚举地址
enum API {
  // 获取全部角色
  ALLROLE_URL = '/admin/acl/role',
  // 新增角色
  ADDROLE_URL = '/admin/acl/role/save',
  // 更新角色
  UPDATE_URL = '/admin/acl/role/update',
  // 获取全部菜单与按钮的数据
  ALLPERMISSTION_URL = '/admin/acl/permission/toAssign/',
  // 给角色分配权限
  ASSIGNPERMISSTION_URL = '/admin/acl/permission/doAssign/',
  // 删除角色
  DELETEROLE_URL = '/admin/acl/role/remove/'

}

// 获取全部角色
export const reqAllRoleList = (
  pageNo: number,
  limit: number,
  roleName: string,
) =>
  request.get<any, RoleResponseData>(
    API.ALLROLE_URL + `/${pageNo}/${limit}/?roleName=${roleName}`,
  )

// 新增或更新角色
export const reqAddOrUpdateRole = (data: Role) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_URL, data)
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data)
  }
}

// 根据角色获取全部菜单与按钮
export const reqAllMenuList = (roleId: number) =>
  request.get<any, MenuResponseData>(API.ALLPERMISSTION_URL + roleId)

// 给角色分配权限
export const reqAssignPermisstion = (roleId: number, permissionId: number[]) =>
  request.post<any, any>(
    API.ASSIGNPERMISSTION_URL + `/?roleId=${roleId}&permissionId=${permissionId}`,
  )

// 删除接口
export const reqDeleteRole = (id: number)=>request.delete<any, any>(API.DELETEROLE_URL + id)